{include file="public/header-static"/}
{include file="public/sidebar"/}
<style>
    ._custom{}
    .communiy{
        text-align: center;
        font-weight: 600;
        font-size: 16px;
        margin-top: 5px;
    }
    .mat-top{
        margin-top: 10px;
        padding-bottom: 20px;
    }
    .d-flex{
        justify-content: space-between;
    }
    .d-str{
        font-size: 15px;
        font-weight: 600;
        margin-top: 10px;
    }
    .card-dth{
        padding-top: 10px;
        position: relative;
    }
    .ma-dfx{
        padding: 10px 20px 20px 20px;
    }
    .pox{
        position: absolute;
        left: 0;
        right: 0;
        top: 67%;
        text-align: center;
        font-size: 15px;
        font-weight: 600;
    }
    .form-control {
        border-color: #f1f1f1 !important;
    }
    .btn.btn-outline-light {
        background: 0 0;
        border-color: #f2f7f9;

        color: #212529;
    }
    .action-right{
        width: 30%;
    }
    .input-group {
        position: relative;
        display: -ms-flexbox;
        display: flex;
        -ms-flex-wrap: wrap;
        flex-wrap: wrap;
        -ms-flex-align: stretch;
        align-items: stretch;
        width: 33%
    }
    .app-action{
        padding-top: 10px !important;
        padding-bottom: 10px !important;
        padding-left: 20px !important;
        border-right: 1px !important;
    }
    .app-block .app-content .app-action, .card, .chat-block {
        -moz-border-radius: 1px;
        border-radius: 1px;

    }
    .z-head{
        display: flex;
        justify-content: space-around;
        width: 50%;
        margin: auto;
        padding-top: 10px;
    }
    .d-lxe{
        display: flex;
        justify-content: space-between;
    }
    .z-left{
        padding-left: 30px;
        padding-top: 55px;
    }
    .unm-s{
        font-weight: 600;
        font-size: 25px;
    }
    .ubn-str{
        color: #999;
        font-size: 15px;
        margin-bottom: 50px;

    }
    .qb-buttom{
        background: #3377FF;
        color: white;
        width: 143px;
        height: 40px;
        line-height: 40px;
        text-align: center;
        border-radius: 3px;
    }

</style>
<div id="main">

    {include file="public/header"/}

    <main class="main-content">

        <div class="container">

            <div class="row jub">
                <div class="col-md-8">
                    <div class="card" style="padding-bottom: 16px">


                        <div class="d-lxe">

                            <div class="z-left">
                                <div class="unm-s">4053</div>
                                <div class="ubn-str">总营收</div>
                                <div class="qb-buttom">查看全部</div>
                            </div>
                            <div class="col-md-7">
                                <div class="z-head">
                                    <div class="z-tab" onclick="catable(1)">每天</div>
                                    <div class="z-tab">每周</div>
                                    <div class="z-tab">每月</div>
                                    <div class="z-tab">每年</div>
                                </div>
                                <div>
                                    <canvas id="myChart" style="height: 200px"></canvas>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="card">
                        <div>
                            <canvas id="post"></canvas>
                        </div>
                        <div class="mat-top">
                            <div class="communiy">上月增长数：100</div>
                            <div class="communiy">环比增长数：200</div>
                        </div>

                    </div>
                </div>
            </div>
            <!-- end::page-header -->
            <div class="app-block">
                <div class="app-content">
                    <div class="app-action">
                        <select class="form-control _custom" id="type_id" aria-required="true" style="width:auto;">
                            <option value="-1">请选择订单类型</option>
                            {volist name="orderType" id="vo"}
                            <option value="{$vo.id}">{$vo.name}</option>
                            {/volist}
                        </select>
                        <select class="form-control _custom" id="status" aria-required="true" style="margin-left: 0.5rem;width:auto;">
                            <option value="-1">请选择订单状态</option>
                            <option value="0">待支付</option>
                            <option value="1">已支付</option>
                        </select>
                        <div class="action-right" style="margin-left: 0.5rem;">
                            <a href="#" class="app-sidebar-menu-button btn btn-outline-light">
                                <i data-feather="menu"></i>
                            </a>
                            <div class="input-group">
                                <input type="text" name="keywords" id="keywords" autofocus="autofocus" value="{$Request.get.keywords}"  class="form-control" placeholder="搜索关键字[订单号]"
                                       aria-describedby="button-addon1">
                                <div class="input-group-append">
                                    <button class="btn btn-outline-light" type="submit" id="button-addon1">
                                        <i data-feather="search"></i>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            {include file="public/page-header"/}
            <div class="row">
                <div class="col-md-12">
                    <div class="card">
                        <div class="card-body">
                                <table id="linkstable" lay-filter="linkstable"></table>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </main>
    {include file="public/footer"/}
</div>
<script type="text/html" id="switchTpl">
    <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="switch_status" {{ d.status == 1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="barDemo">
    {{# if(d.status == 1) { }}
        <button class="btn btn-sm btn-outline-secondary" disabled style="color: #fff;background: #76CCFE;">已支付</button><br>
    {{# } else { }}
        <button lay-event="orderChangeStatus" class="btn btn-sm btn-outline-secondary">待支付</button><br>
    {{# } }}
    <button lay-event="del" class="btn btn-sm btn-outline-secondary">删除</button>
</script>
<script src="__STATIC__/assets/js/custom.js"></script>
<script src="__STATIC__/vendors/charts/chartjs/chart.min.js"></script>
<script>
    function catable(type) {
        console.log(type);
    }
    new Chart(document.getElementById("post"), {
        type: 'doughnut',
        data: {
            labels: ["本周", "昨日", "实时"],
            datasets: [
                {
                    label: "Population (millions)",
                    backgroundColor: ["#97D70D", "#F69136","#347AF7"],
                    data: [100,100,100]

                }
            ]
        },

        options: {

            title: {

                display: true,

                text: '帖子统计'

            }

        }

    });

    $(function () {

        var ctx = document.getElementById("myChart").getContext('2d');
        var data = {
            labels : ["1","2","3","4","5","6"],
            datasets : [
                {
                    label:'2017',
                    backgroundColor:'rgba(40,161, 121, 0.1)',
                    borderColor: "#36A2EB", //路径颜色
                    pointBackgroundColor: "#1BB8FA", //数据点颜色
                    pointBorderColor: "#fff", //数据点边框颜色
                    data : [0,15,10,35,10,0],
                    borderWidth:'2',
                    pointRadius:0

                },

            ],

        }
        var myLineChart = new Chart(ctx, {
            type: 'line',
            data: data,
            options: {
                scales: {
                    yAxes: [{
                        tension: 0,
                    }]
                }
            }
        });



    });

    function del(id) {
        $.post("{:url('/console/delOrder')}", {id:id}, function(data) {
            if(data['code']!=1)
            {
                toastr.error(data['msg']);
            }else{
                window.location.reload();
            }
        });
    }

    function orderChangeStatus(id) {
        $.post("{:url('/console/orderChangeStatus')}", {id:id}, function(data) {
            if(data['code']!=1)
            {
                toastr.error(data['msg']);
            }else{
                window.location.reload();
            }
        });
    }

    // layui插件
    layui.use('table', function(){
        var table = layui.table
            ,form = layui.form;
        // 表格初始化
        table.render({
            elem: '#linkstable'
            ,url: '{:url("/console/order")}'
            ,method:'post'
            ,page: true //开启分页
            ,cols: [[
                {field:'id', title:'ID'}
                ,{field:'order_no', title:'订单号'}
                ,{field:'buy_message', title:'购买人信息'}
                ,{field:'member_message', title:'会员信息'}
                ,{field:'tname', title:'会员类型'}
                ,{field:'create_time', title:'创建时间'}
                ,{field:'pay_time', title:'支付时间'}
                // ,{field:'desc', title:'订单描述'}
                ,{field:'rightbtn', title:'操作', toolbar: '#barDemo'}
            ]],
            parseData: function(res){
                return {
                    "code": res.data.code,
                    "msg": res.data.msg,
                    "count": res.data.count,
                    "data": res.data.list
                };
            }
        });
        table.on('tool(linkstable)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('确定删除该数据么？', {icon: 3, title:'提示'}, function(index){
                    obj.del();
                    layer.close(index);
                    del(data.id);
                });
            }else if(obj.event === 'orderChangeStatus'){
                layer.confirm('修改订单状态？', {icon: 3, title:'提示'}, function(index){
                    layer.close(index);
                    orderChangeStatus(data.id);
                });
            }
        });

        // 搜索
        $('#button-addon1').on('click', function(){
            var keywords= $("#keywords").val();
            var type_id = $("#type_id option:selected").val();
            var status = $("#status option:selected").val();
            console.log(keywords,type_id,status)
            // return false
            table.reload('linkstable', {
                url: '{:url("/console/order")}'
                ,where: {
                    keywords : keywords,type_id:type_id,status:status // 搜索参数
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        form.on('switch(switch_status)', function(obj){
            $.post("{:url('/console/todayChangeStatus')}",{id:obj.value,field:'status'},function(){});
        });
    });

    // 图片放大
    function show_img(element) {
        var elements = $(element).find("img");
        //页面层
        layer.open({
            type: 1,
            title: '图片',
            anim: 2,
            // area: ['800px','500px'], //宽高 t.width() t.height()
            shadeClose: true, //开启遮罩关闭
            end: function (index, layero) {
                return false;
            },
            content: '<div style="text-align:center"><img src="' + $(elements).attr('src') + '" /></div>'
        });
    }
</script>